﻿using System.Collections.Generic;
using Godot.core.io;
using Godot.core;

namespace Godot.modules.gdscript
{
    public partial class GDParser
    {
        private GDTokenizer _tokenizer;
        private GDParser.Node _head;
        private GDParser.Node _list;

        private bool _error_set;
        private string _error;
        private int _error_line;
        private int _error_column;

        private List<int> _tab_level;
        private string _base_path;
	    private PropertyInfo _current_export;


        public GDParser()
        {
            _tab_level = new List<int>();
            _current_export = new PropertyInfo();
        }

        public Node get_parse_tree()
        {
            return _head;
        }

        public Error parse_bytecode(List<byte> p_bytecode,string p_base_path) 
        {
	        GDTokenizerBuffer tb = new GDTokenizerBuffer();
	        tb.set_code_buffer(p_bytecode);
	        _tokenizer = tb;
            Error ret = _parse(p_base_path);
	        _tokenizer = null;
	        return ret;
        }

        public Error parse(string p_code, string p_base_path) 
        {
	        GDTokenizerText tt =new GDTokenizerText();
	        tt.set_code(p_code);
	        _tokenizer = tt;
	        Error ret = _parse(p_base_path);
	        _tokenizer = null;
	        return ret;
        }

        public void clear()
        {
	        _error_set=false;
	        _tab_level.Clear();
            _tab_level.Add(0);
	        _error_line = 0;
	        _error_column = 0;
	        _current_export.type = Variant.Type.NIL;
	        _error = "";
        }
    }
}
